using System;
using System.Web;

namespace THANHTUNGO.Portal.Components.Helpers
{
    public class UrlRewriter : IHttpModule
    {
        #region IHttpModule Members

        public void Init(HttpApplication context)
        {
            if (context != null) context.BeginRequest += Context_BeginRequest;
        }

        public void Dispose()
        {
        }

        #endregion

        private static void Context_BeginRequest(object sender, EventArgs e)
        {
            
            HttpApplication app = (HttpApplication) sender;
            string url = app.Request.RawUrl.ToLower();
            
            if (url.Contains("/signin.aspx"))
            {
                app.Context.RewritePath("Default.aspx", "", "cid=SignIn");
            } 
            else if (url.Contains("/register.aspx"))
            {
                app.Context.RewritePath("Default.aspx", "", "cid=Register");
            }
            else if (url.Contains("/registercompleted.aspx"))
            {
                app.Context.RewritePath("Default.aspx", "", "cid=RegisterCompleted");
            }
            else if (url.Contains("/activeuser.aspx"))
            {
                app.Context.RewritePath("Default.aspx", "", "cid=ActiveUser");
            }
            else if (url.Contains("/changepassword.aspx"))
            {
                app.Context.RewritePath("Default.aspx", "", "cid=ChangePassword");
            }
            else if (url.Contains("/passwordrecovery.aspx"))
            {
                app.Context.RewritePath("Default.aspx", "", "cid=PasswordRecovery");
            }

        }
    }
}